<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>管理员表编辑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/css/news.css"/>
    <style>
        li {
            list-style: inherit !important;
        }
    </style>
</head>

<body class="childrenBody">
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">ID</label>
        <div class="layui-input-block">
            <input type="text" name="title" readonly="readonly" class="layui-input"
                   id="id">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="title" placeholder="请输入姓名" class="layui-input"
                   id="realname">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">登录名</label>
        <div class="layui-input-block">
            <input type="text" name="title" placeholder="请输入登录名" class="layui-input"
                   id="username">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="text" name="title" placeholder="请输入密码" class="layui-input"
                   id="password">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <a class="layui-btn layui-btn-normal" lay-filter="demo1" id="edit">立即修改</a>
            <a class="layui-btn layui-btn-primary close">取消</a>
        </div>
    </div>
</form>
<script type="text/javascript" src="../../js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/wangEditor.js"></script>
<script type="text/javascript" src="../../js/basic.js"></script>
<script>


    layui.use(['form'], function () {
    });


    //点击取消关闭当前弹窗
    $(".close").click(function () {
        layer.closeAll("iframe");
        parent.location.reload();
    })

    $("#edit").click(function () {
        var id = GetQueryString("id");

        if ($("#realname").val() == "") {
            layer.msg('请输入姓名', {icon: 2});
            return;
        }
        if ($("#username").val() == "") {
            layer.msg('请输入登录名', {icon: 2});
            return;
        }
        if ($("#password").val() == "") {
            layer.msg('请输入密码', {icon: 2});
            return;
        }
        if ($("#status").val() == "") {
            layer.msg('请输入状态 0正常 -1冻结 -10删除', {icon: 2});
            return;
        }

        $.ajax({
            type: "post",
            url: "/admin/update",
            data: {
                realname: $("#realname").val(),
                username: $("#username").val(),
                password: $("#password").val(),
                id: id
            },
            dataType: "json",
            success: function (data) {
                if (data.status == 0) {
                    var index = parent.layer.getFrameIndex(window.name);
                    var index = top.layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.8});
                    setTimeout(function () {
                        top.layer.close(index);
                        top.layer.msg("修改成功！");
                        layer.closeAll("iframe");
                        //刷新父页面
                        parent.location.reload();
                    }, 500);
                    //   $("#newsAdd").hide();
                    layer.close(index); //如果设定了yes回调，需进行手工关闭
                } else {
                    layer.msg(data.msg, {icon: 1});
                }
            }
        });
    });


    $(document).ready(function () {
        var id = GetQueryString("id");
        $.ajax({
            type: "post",
            url: "/admin/info",
            data: {
                id: id
            },
            dataType: "json",
            success: function (data) {
                if (data.status == 0) {

                    $("#id").val(data.result.id);


                    $("#createTime").val(data.result.createTime);


                    $("#realname").val(data.result.realname);


                    $("#username").val(data.result.username);


                    $("#password").val(data.result.password);


                    $("#status").val(data.result.status);

                } else {
                    layer.msg(data.msg, {icon: 1});
                }
            }
        });

    });

</script>
</body>

</html>